package inner;

//实例内部类
public class Test {
    public static void main(String[] args) {
        //获取内部类对象
        //法一
        OutClass outClass = new OutClass();  //先得到outClass对象
        OutClass.InClass inClass = outClass.new InClass(); //用outClass对象引用new inClass对象得到内部类对象

        //法二  //OutClass.InClass是它的类型
        OutClass.InClass inClass2 = new OutClass().new InClass();
    }
}
//外部类
class OutClass{
    public int data1=1;
    int data2=2;
    public static int data3=3;

    public void func(){
        System.out.println("OutClass::func()");
    }
    /**
     * 1、如何获取实例内部类的对象
     * 2、实例内部类中不能有静态的成员变量，
     *    因为实例内部类中static修饰的成员变量会在外部类加载时就执行，而内部类在后执行，就出错了
     */
    //实例内部类
    class InClass{
        public int data4=4;
        int data5=5;
        //public static int data6=6;

        public void func(){
            System.out.println("InClass::func()");
        }
    }
}


//实例内部类
package inner;

public class Test {
    public static void main(String[] args) {
        OutClass outClass = new OutClass(); //1>先new一个外部类对象
        outClass.outfunc();  //2>再通过外部类对象访问外部方法
    }
}
//外部类
class OutClass{
    public int data1=1;
    public void func(){
        System.out.println("OutClass::func()");
    }

    //实例内部类
    class InClass{
        public int data1=11;
        public void func() {
            System.out.println(InClass.this.data1); //内部类访问内部类成员变量
            System.out.println("InClass::func()");
        }
    }
    public void outfunc(){
        System.out.println("OutClass::func()");
        InClass inClass = new InClass(); //3>先new一个实例内部类
        inClass.func();//4>
    }
}

//静态内部类
package inner;

public class Test {
    public static void main(String[] args) {
        OutClass.InClass inClass = new OutClass.InClass();
    }
}
//外部类
class OutClass{
    public int data1=1;
    int data2=2;
    public static int data3=3;

    public void func(){
        System.out.println("OutClass::func()");
    }
    /**
     * 1、如何获取静态内部类的对象？
     */
    //静态内部类
    static class InClass{
        public int data4=4;
        int data5=5;
        //public static int data6=6;

        public void func(){
            System.out.println("InClass::func()");
        }
    }
}

//对象的打印
class Person {
    String name;
    String gender;
    int age;
    public Person(String name, String gender, int age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                '}';
    }

    //main方法在哪就从哪开始执行
    public static void main(String[] args) {
        Person person = new Person("Jim","男", 18);
        System.out.println(person);
    }
}